home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PsL Monthly 1993 December
/
PSL Monthly Shareware CD-ROM (December 1993).iso
/
prgmming
/
dos
/
basic
/
langwn1.exe
/
SAMPLE04.BAS
< prev
next >
Wrap
BASIC Source File
|
1993-03-20
|
53KB
|
1,422 lines
' giving your user a set of scrollable lists, with files and
' sub-directories that can be selected, is a common GUI technique.
' SAMPLE04.BAS shows how to use LangWin to achieve this effect.
' a mode 4 (wallpaper) window is used as background.
' several unmovable windows (of the same
' color as background window) with no shadows,
' are created to provide several
' scrollable lists in "one" window.
' the directory and file access routines are used to create
' scrollable lists of files and sub-directories. by clicking
' on a sub-directory, you can change into it, and it's contents
' (files and directories) will then be displayed in the scrollable
' lists.
' this sample also shows how to use an error recovery routine
' in the main module to detect when a drive is not ready,
' and allow the user to retry or quit the operation.
' subroutine DoFiles (which also calls ChgPath and SortIt) is
' meant to be a stand-alone routine that you can copy and use
' in your own programs. it implements techniques to create
' a "menu" with drives, sub-directories, files, and the current directory.
' these can be scrolled, selected, and/or changed.
DECLARE FUNCTION ChgPath% (NewPath$) ' changes to new path
DECLARE SUB DoFiles () ' menu of files, dirs, drives
DECLARE SUB SortIt (s$()) ' bubble sort
DECLARE SUB Main () ' main window
DECLARE FUNCTION VidType% () ' gets type of monitor
DECLARE SUB ProcessFiles (Qual$, Text$()) ' sample routine to process files
' must compile with qb /ah /L langwin
'$DYNAMIC make all arrays dynamic
DEFINT A-Z
'$INCLUDE: 'LANGWIN.BI' ' TYPE, DECLARE and COMMON definitions for LangWin.
' NOTE: LANGWIN.BI contains all definitions found
' in QB.BI, so include for QB.BI is not needed.
CLEAR , , 5000 ' set stack at 5000 bytes
'---------------------------------------------------------------
' first see if EGA or VGA monitor
mm = VidType
IF mm <> 3 AND mm <> 4 THEN
BEEP
PRINT
PRINT "LangWin's GUI only supports EGA and VGA."
PRINT
END
END IF
'----------------------------------------------------------------
' SHARED VARIABLES
' - dlett$: MUST contain the letter of the drive that is being
' referenced by the GetCurDir$ function.
' if the drive is not ready, the error routine in the main module will
' get control and use dlett$ in its error message.
' - ignor: used a flag for the error routine. when a drive is selected but
' not ready, the error routine gets control and opens a window that
' contains a RETRY button and possinly an IGNORE button.
' if ignor=0 then IGNORE button is NOT displayed; else it is displayed.
' selecting RETRY will cause the instruction that generated the
' "not ready" error to be retried. selecting IGNORE will pass control
' to the instruction after the one generating the error condition.
' - Ldrives: number of logical drives on the system
' - OneFlop: flag set (TRUE) if system has one floppy, else FALSE
DIM SHARED dlett$, ignor, Ldrives, OneFlop
'-----------------------------------------------------------------
ON ERROR GOTO ErrorTrap ' enable error routine
'-----------------------------------------------------------------
' get attribute from current screen so it can be restored upon exit
OrigAttr = SCREEN(1, 1, 1)' save original attribute from row 1, col 1
'-------------------------------------------------------------------
' if WIDTH command is used, it must be placed before call to LangWinInit
' because code in LangWinInit extracts max rows/cols from screen and saves
' in global variables.
WIDTH 80, 25
'----------------------------------------------------------------------
' these variables MUST be defined BEFORE call to LangWinInit.
' keep these as low as possible to conserve memory at run time.
MaxWindows = 10 ' max simultaneous open windows
MaxButtons = 40 ' max number of objects (including text labels) active
MaxTextLines = 200 ' maximum number of text lines in any scrollable win
MaxTextWins = 4 ' max windows that can have scrollable text
' must be <= MaxWindows
LOCATE , , 0 ' start with hidden text cursor
SCREEN 0, , 0, 0 ' text mode
CALL LangWinInit ' initialize (if mouse exists, it will be displayed)
' if you get "subscript out of range" error while
' in this routine, be sure you called QB with /ah.
' then try reducing the value of MaxWindows.
' check the WIDTH command; reduce number of columns,
' and/or number of rows.
'---------------------------------------------------------------------
' get actual number of logical drives on the system
' get # drives from ChangeDrive (i.e., int 21h, function 0Eh).
' value will be max of 5 or # logical drives specified
' in LASTDRIVE parm in config.sys (i.e., LASTDRIVE=c will cause ChangeDrive
' to return 5, not 3, as # logical drives - that's a DOS quirk, not mine).
' LASTDRIVE=g will cause ChangeDrive to return a 7.
' drives specified in LASTDRIVE parm, however, might not be actual
' number of drives on system (LASTDRIVE=z doesn't mean you have 26 drives)
' so, after we get LASTDRIVES value, we must determine how many logical
' drives really exist (without attempting to read from them
' which could produce a drive not ready error) - that is, we need to know
' how many drives are actually configured on the system, not how many
' are ready at this moment.
dd$ = GetCurDrive$ ' current default drive
Ldrives = ChangeDrive(dd$) 'get LASTDRIVES value
' now see how many drives are actually there
' step through each drive (starting with #1) and try to
' change to it with ChangeDrive. if successful, continue with loop.
' if unsuccessful, then previous drive was last drive on the system.
FOR i = 1 TO Ldrives
dl$ = CHR$(ASC("A") - 1 + i) ' compute a drive letter
x = ChangeDrive(dl$) ' try to change to it
IF x < 0 THEN ' successful?
Ldrives = i - 1 ' can't change to drive i, change value of ldrives
EXIT FOR ' stop scan
END IF
NEXT
x = ChangeDrive(dd$) ' now change back to original drive
'--------------------------------------------------------------------
' on systems with only one physical floppy drive, it can be logically
' referenced as both A: and B: (dos handles this).
' however, if the A: drive is "active" and you try and access the B: drive,
' dos will display the following message:
' "Insert diskett for drive B: and press any key when ready"
' unfortunately, you cannot control the placement of this message and it will
' ruin an otherwise attractive display of windows.
' if the system has one floppy, and either A: or B: is selected by user,
' i assume that both drive letters refer to the same physical drive,
' and i first make the appropriate logical letter "active" before the
' drive is accessed. this should avoid the dos message.
' a not ready condition will be detected, and an error window opened,
' if the A: or B: drive (which has been made active) is not ready
' (i.e., does not have a floppy inserted and the door closed).
' the byte at &H504 is used to make either A: or B: active.
' if it is set to 0, then A: is active; if 1 then B: is active
' (assuming that there is only one floppy on the system).
' the word at &H410 contains info on system equipment.
' if bit 0 is set, then the system has floppies.
' in that case, bits 6 & 7 indicate the number of floppies minus 1
' (i.e., if bits 6 & 7 are 0, then system has 1 floppy drive).
' first, lets see if this system has only one floppy drive
OneFlop = FALSE ' default for flag
DEF SEG = 0 ' establish addressability to low memory
IF (PEEK(&H410) AND &H1) = 1 THEN ' test bit 0 to see if any floppies
' floppies exist, see how many
' set flag if only one
IF (PEEK(&H410) AND &HC0) = 0 THEN OneFlop = TRUE
END IF
DEF SEG ' restore addressability
' the OneFlop flag will